<div class="layui-row">
    <div class="layui-col-xs6">
        <!--单选项-->
        <li class="layui-form-item language">
            <label class="layui-form-label">生成语言：</label>
            <div class="layui-input-block">
                <? foreach ($language_array as $k => $v){?>
                    <input type="radio" name="ai_language[]"  value="<?echo $v?>"     title="<?echo $v?>"
                        <? if($v==$data['language'])   {echo "checked";} ?>>
                    <?;}?>
                <em class="explain">(选择立即发布，以上信息才能在前台显示；选择暂未发布，只对以上信息进行保存，不在前台显示)</em>
            </div>
        </li>


        <li class="layui-form-item name">
            <label class="layui-form-label">字数限制：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"  name="ai_limitation"  value="<? echo $data['limitation'] ?>">
                <em class="explain">不限制则留空</em>
            </div>
        </li>


        <li class="layui-form-item name">
            <label class="layui-form-label">生成数量：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"  name="amount"  value="10">
            </div>
        </li>



        <!--普通的input文本输入-->
        <li class="layui-form-item name">
            <label class="layui-form-label">公司名称：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"  name="ai_company"  value="<? echo $data['company'] ?>">
                <em class="explain">(<u style="color:red">*必填项目</u>, 填写标题) </em>
            </div>
        </li>


        <!--普通的input文本输入-->
        <li class="layui-form-item name">
            <label class="layui-form-label">产品名称：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"  name="ai_product"  value="<? echo $data['product'] ?>">
            </div>
        </li>





    </div>
    <div class="layui-col-xs6">


        <div class="layui-form-item">
            <label class="layui-form-label">自家行业</label>
            <div class="layui-input-block" >
                <? foreach ($industry_type_array as $k => $v){?>
                    <input type="checkbox" name="ai_from_industry_type[]"
                           value="<?echo $v?>"     title="<?echo $v?>"
                           lay-skin="primary"
                        <? if(in_array($v,$now_data_from_industry_type_array))   {echo "checked";} ?>>
                    <?;}?>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">目标行业</label>
            <div class="layui-input-block" >
                <? foreach ($industry_type_array as $k => $v){?>
                    <input type="checkbox" name="ai_for_industry_type[]"
                           lay-skin="primary"
                           value="<?echo $v?>"     title="<?echo $v?>"
                        <? if(in_array($v,$now_data_for_industry_type_array))   {echo "checked";} ?>>
                    <?;}?>
            </div>
        </div>


        <!--普通的textarea多行文本输入-->
        <li class="layui-form-item introduce">
            <label class="layui-form-label">要求：</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" name="ai_requirement"  ><?echo  $data['requirement']?></textarea>
                <em class="explain">(填写本文的概述)</em>
            </div>
        </li>


    </div>
</div>

<hr/>
<div><button class="layui-btn layui-btn-xs" id="js_creat_by_api"> 生成内容 </button> </div>



<script>
$('#js_creat_by_api').click(function () {
    var $button = $(this);

    // 禁用按钮
    $button.prop('disabled', true);
    console.log("js_creat_by_api");

    //判断
    $.ajax({
        type: "POST",
        url: "/api/system/tongyiqianwen/get_result.php",
        data: {
            "action": "creat_by_api",
            "data": {
                "language": $('input[name="ai_language[]"]:checked').val(),
                "limitation": $('input[name="ai_limitation"]').val(),
                "amount": $('input[name="amount"]').val(),
                "company": $('input[name="ai_company"]').val(),
                "product": $('input[name="ai_product"]').val(),
                "from_industry_type": $('input[name="ai_from_industry_type[]"]:checked').serializeArray(),
                "for_industry_type": $('input[name="ai_for_industry_type[]"]:checked').serializeArray(),
                "requirement": $('textarea[name="ai_requirement"]').val()
            }
        }
    }).done(function (data) {
        console.log("Request successful:", data);
        if (data.code == 200) {
            alert(data.msg);
        } else {
            alert("Unexpected response code: " + data.code);
        }
    })
    .fail(function (jqXHR, textStatus, errorThrown) {
        console.log("Request failed:", textStatus, errorThrown);
        alert("error");
    })
    .always(function () {
        // 无论请求成功还是失败，都启用按钮
        $button.prop('disabled', false);
    });
});
</script>


